package com.dongdongshop.controller;
//商品审核

import com.alibaba.fastjson.JSONObject;
import com.dk.data.R;
import com.dk.util.PageResult;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.pojo.TbSpecificationOption;
import com.dongdongshop.service.TbgoodService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
//审核驳回生产者
@Controller
@RequestMapping("good")
public class TbgoodController {

    @DubboReference
    TbgoodService tgs;

    @Autowired
    RocketMQTemplate rocketMQTemplate;


    //页面跳转
    @RequestMapping("tiao")
    public String tiao (){
        return "admin/goods";
    }



    //分页查询全部
    @RequestMapping("getall")
    @ResponseBody
    public Map<String, Object> getall(@RequestParam(defaultValue = "1") Integer pagenum, @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult p = tgs.getall(pagenum, pagesize);
        Map<String, Object> m=new HashMap<>();
        m.put("rows",p.getRows());
        m.put("total",p.getTotal());
        return  m;
    }

    //审核通过
    @RequestMapping("tongguo")
    @ResponseBody
    public R tongguo(String tbgoods){
        List<TbGoods> tg = JSONObject.parseArray(tbgoods, TbGoods.class);
        tgs.tongguo(tg);
        List<Long> ls=new ArrayList<>();//所有的id
        for(int i=0;i<tg.size();i++){
            ls.add(tg.get(i).getId());
        }
        String s=JSONObject.toJSONString(ls);
        rocketMQTemplate.convertAndSend("dkxiang",s);//生产者发送消息
        return R.ok();
    }


    //审核驳回
    @RequestMapping("bohui")
    @ResponseBody
    public R bohui(String tbgoods){
        List<TbGoods> tg = JSONObject.parseArray(tbgoods, TbGoods.class);
        tgs.tongguo(tg);
        return R.ok();

    }




}
